home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / SysIO / write.c < prev   
C/C++ Source or Header  |  1990-04-07  |  1KB  |  57 lines

  1. /*
  2.  * Libraries and headers for PDC release 3.3 (C) 1989 Lionel Hummel.
  3.  * PDC Software Distribution (C) 1989 Lionel Hummel and Paul Petersen.
  4.  * PDC I/O Library (C) 1987 by J.A. Lydiatt.
  5.  *
  6.  * This code is freely redistributable upon the conditions that this 
  7.  * notice remains intact and that modified versions of this file not
  8.  * be included as part of the PDC Software Distribution without the
  9.  * express consent of the copyright holders.  No warrantee of any
  10.  * kind is provided with this code.  For further information, contact:
  11.  *
  12.  *  PDC Software Distribution    Internet:                     BIX:
  13.  *  P.O. Box 4006             or hummel@cs.uiuc.edu            lhummel
  14.  *  Urbana, IL  61801-8801       petersen@uicsrd.csrd.uiuc.edu
  15.  */
  16.  
  17. /* write - writes to a file */
  18.  
  19. #include    <errno.h>
  20. #include    <fcntl.h>
  21. #include    <exec/types.h>
  22. #include    <libraries/dos.h>
  23. #include    <functions.h>
  24.  
  25. extern void Chk_Abort();
  26.  
  27. write(fd, buf, bufsize)
  28. int   fd;
  29. char *buf;
  30. int   bufsize;
  31. {
  32.     struct _device *p;
  33.     extern struct _device *_devtab;
  34.  
  35.     long err;
  36.  
  37.     Chk_Abort();
  38.  
  39.     p = &_devtab[fd];
  40.     if ( !( 0 <= fd && fd < _numdev) || !p->_fileHandle) {
  41.         errno = EBADF;
  42.         return -1;
  43.     }
  44.  
  45.     if ( (p->_mode & 0x03) == O_RDONLY) {
  46.         errno = EINVAL;
  47.         return -1;
  48.     }
  49.  
  50.     if ((err = Write((struct FileHandle *) p->_fileHandle, buf, (long)bufsize)) == -1 ) {
  51.         errno = IoErr();
  52.         return -1;
  53.     }
  54.  
  55.     return (int)err;
  56. }
  57.